// pages/report/event_report/event_report.js
import {
  Alert,
  Confirm,
  Toast
} from 'wuss-weapp';
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: app.globalData.appTitle,
    })
    let currDate = app.getNowFormatDate().split(" ")[0];
    this.setData({
      theme: app.globalData.theme,
      business_start: currDate,
      business_end: app.addDayDate(currDate, 60),
      currentDataTime: currDate,
      defaultEndTime: app.addDayDate(currDate, 1),
      start_time: currDate,
      end_time: app.addDayDate(currDate, 1)
    });
    app.setNavigationBarColor();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 选择事件
   */
  handleSelect: function (e) {
    let [type, value] = [e.currentTarget.dataset.type, e.detail.value];
    console.error(value)
    if (type == "startTime") {
      this.setData({
        start_time: value.format('YYYY-MM-DD')
      });
    } else if (type == "endTime") {
      this.setData({
        end_time: value.format('YYYY-MM-DD')
      });
    }
  },
  /**
   * 提交
   */
  formSubmit: function (e) {
    let params = e.detail;
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    if (!app.removeAllSpace(params.theme)) {
      this.setData({
        error: "请输入议事主题!"
      });
    } else if (!app.removeAllSpace(params.content)) {
      this.setData({
        error: "请输入议事内容!"
      });
    } else if (new Date(this.data.end_time).getTime() - new Date(this.data.start_time).getTime() <= 0){
      this.setData({
        error: "议事结束时间大于开始时间!"
      });
    } else {
      app.confirm('提示', '你确定要提交吗？').then(result => {
        wx.showLoading({
          title: '保存中...',
        })
        params["start_time"] = this.data.start_time;
        params["end_time"] = this.data.end_time;
        params["url"] = app.globalData.urlMicro + "/v1/conference";
        params["type"] = 1;
        params["area_code"] = app.globalData.parentAreaCode;
        params["people_id"] = app.globalData.userInfo["people_id"];
        params["creator_id"] = app.globalData.userInfo["user_id"];
        params["creator_name"] = "超级管理员";
        app.wxPostRequest("/wechart/life/postMicroservice", params).then(result => {
          Toast.show({
            type: 'success',
            message: "提交成功!",
          });
          setTimeout(() => {
            prevPage.setData({
              formPage:"add"
            })
            wx.navigateBack({
              delta: getCurrentPages()
            })
          }, 1000);
        });
      });
    }
  }
})